<?php 

    include('functions.php');
    
    $error_bar = '';
    
    if(isset($_GET['username']) && !empty($_GET['username']) && isset($_GET['password']) && !empty($_GET['password'])) {
        $username = trim($_GET['username']);
        $password = trim($_GET['password']);
        
        $content = curl("http://www.djmaxcn.com/login.asp?txtUserid={$username}&txtPassword={$password}", true);
        
        list($header, $body) = explode("\r\n\r\n", $content);
        
        $json = json_decode($body);
        
        if($json->CODE!=0) {
            switch($json->CODE) {
                case '1':
                    $error = '请输入正确的帐号';
                    break;
                case '2':
                    $error = '请输入正确的密码';
                    break;
                case '3':
                    $error = '帐号不存在';
                    break;
                case '4':
                    $error = '呵呵, 密码错误';
                    break;                       
            }
            jump('login.php', "err={$error}");
            exit();
        }

        preg_match("/set\-cookie:([^\r\n]*)/i", $header, $matches);

        $cookie = $matches[1];
        
        setcookie('loginInfo', $cookie);

        jump('index.php');
        exit($cookie);
        
    } elseif(isset($_GET['err']) && !empty($_GET['err'])) {
        $error_bar = "<p style=\"color:red;\">{$_GET['err']}</p>";
    }
    
    getHead('登录');

echo <<<HTML
<p style="font-size: 13px; color: #999;">您所输入的信息将会直接被提交到DJMAX服务器进行验证，我们承诺决不存储您的帐号和密码。</p>
{$error_bar}
<form method="get" action="?">
    <p>帐号:<input type="text" name="username"/></p>
    <p>密码:<input type="password" name="password"/></p>
    <p><input type="submit" value="登录" /></p>
</form>
HTML;
 
    getFoot();